// TypeScript type definitions for the form designer
export interface FormField {
  id: string
  type: FieldType
  label: string
  name: string
  required: boolean
  defaultValue?: string | number | boolean | null
  options?: Option[]
  validation?: ValidationRule[]
  props?: Record<string, string | number | boolean>
  // 表格相关属性
  showInTable?: boolean
  tableWidth?: string
  // API选项相关属性
  optionSource?: 'manual' | 'api'
  apiUrl?: string
  apiMethod?: 'get' | 'post'
  apiDataPath?: string
  apiLabelField?: string
  apiValueField?: string
}

export enum FieldType {
  TEXT = 'text',
  TEXTAREA = 'textarea',
  NUMBER = 'number',
  SELECT = 'select',
  RADIO = 'radio',
  CHECKBOX = 'checkbox',
  DATE = 'date',
  DATETIME = 'datetime',
  FILE = 'file',
}

export interface Option {
  label: string
  value: string | number | boolean
}

export interface ValidationRule {
  type: string
  message: string
  value?: string | number | boolean
}

export interface FormConfig {
  fields: FormField[]
  layout: FormLayout
  validation: FormValidation
}

export interface FormLayout {
  columns: number
  labelWidth: string
  size: 'large' | 'default' | 'small'
}

export interface FormValidation {
  rules: Record<string, ValidationRule[]>
}